package com.ninetyfour.app;

import android.os.Bundle;
import android.content.Context;
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugin.common.MethodChannel;
import androidx.annotation.NonNull;

public class MainActivity extends FlutterActivity {
    @Override
    public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
        super.configureFlutterEngine(flutterEngine);
        new MethodChannel(flutterEngine.getDartExecutor().getBinaryMessenger(), "com.example.qysdk")
            .setMethodCallHandler((call, result) -> {
                if (call.method.equals("showQYSession")) {
                    // 获取 Flutter 传递过来的参数
                    String userId = call.argument("userId");
                    String phone = call.argument("phone");
                    String email = call.argument("email");
                    String version = call.argument("version");

                    // 将参数传递给 MainApplication 的方法
                    ((MainApplication) getApplication()).openCustomerService(MainActivity.this, userId, phone, email, version); 
                    result.success(null);
                } else {
                    result.notImplemented();
                }
            });

        new MethodChannel(flutterEngine.getDartExecutor().getBinaryMessenger(), "umeng_push")
        .setMethodCallHandler((call, result) -> {
            if (call.method.equals("register")) {
                ((MainApplication) getApplication()).registerService(MainActivity.this); 
                result.success(null);
            } else {
                result.notImplemented();
            }
        });
    }
}
